package cn.xuyun.cc.tcp;

import java.net.InetSocketAddress;
import java.util.concurrent.Executors;

import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;

import cn.xuyun.cc.tcp.coder.MyDecoder;


public class TcpServer {

	
		public static void main(String[] args) throws Exception{
			

			
	// Configure the server.
			ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));

			 // Set up the event pipeline factory.
	        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
	            public ChannelPipeline getPipeline() throws Exception {
	                return Channels.pipeline(new MyDecoder());
	            }
	        });
			
			
			// Bind and start to accept incoming connections.
			int port = 4000;
			if (args.length > 0) {
				port = Integer.parseInt(args[0]);
			}
			bootstrap.bind(new InetSocketAddress(port));
			bootstrap.bind(new InetSocketAddress(4001));//控制台端口
			
		}
		
		
}
